home *** CD-ROM | disk | FTP | other *** search
- Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
- From: grantp@usa.pipeline.com(Pete Grant)
- Newsgroups: comp.lang.c++
- Subject: Re: execution speed of c++ versus c
- Date: 20 Apr 1996 18:03:25 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4lb8td$3o4@news1.h1.usa.pipeline.com>
- References: <4l8k1q$mji@news.missouri.edu>
- NNTP-Posting-Host: 38.8.60.8
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete Grant)
- X-Newsreader: Pipeline v3.5.0
-
- On Apr 19, 1996 17:55:06 in article <execution speed of c++ versus c>,
- 'dons@math.missouri.edu (Don Steiger)' wrote:
-
-
- >Has anybody run any tests comparing the execution speeds of optimized c++
- code
- >versus optimized c code.
-
- I'm probably going to kick myself for responding to this topic
- which pops up every month..... but, it's Saturday :-)
-
- Yes, I've run tests, and have found that equivalent code in
- C and C++, compiled by equivalent compilers, will run at the
- same speed. Period.
-
- Now, what is (and isn't) equivalent?
-
- It's easy for new and lazy programmers to generate inefficient
- code -- more so in C++ than in C. C, therefore, sometimes
- appears to be faster.
-
- C++ has possibilities for optimizations that are not available
- in C. For example, inline functions. A C advocate will
- point out that macros can be used to achieve the same
- efficiency. This is true, but who wants to deal with
- macros -- especially complex ones written by someone else?
- C++, therefore, appears to be faster.
-
- If trying to write using OO paradigm in both languages,
- C++ has the potential to be faster by a small and insigni-
- ficant margin. Virtual function dispatch is usually
- a nanosecond or two faster than a case statement in C.
-
- In the past, C compilers were better optimized than C++
- compilers. After all, C had been around for years. This,
- IMHO, is no longer true to any significant extent.
-
- The bottom line: If you're worried about efficiency,
- concentrate on finding the appropriate algorithms and
- profile your system to the hilt. The returns you get
- from that are an order of magnitude greater than from
- choosing one language over the other.
-
- --
- Pete Grant
- Kalevi, Inc.
- Software Engineering & development
-